package com.hnust.service.impl;

import com.hnust.dao.TeacherDao;
import com.hnust.domain.CollegeAdmin;
import com.hnust.domain.SchoolAdmin;
import com.hnust.service.TokenService;
import com.hnust.util.JwtToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author：gh
 * @date：2020/10/30
 */
@Service("tokenService")
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TeacherDao teacherDao;

    @Override
    public Boolean verifyToken(String token) {
        //判断身份，出现异常直接不通过
        try{
            //验证信息，去dao中查询
            Map<String,String> map=new HashMap<>();
            map= JwtToken.verifyToken(token);
            int num = teacherDao.findTeacherByIdPass(map.get("id"),map.get("password"));
            //不为空则验证通过
            return num == 1;
        }catch (Exception e){
            return false;
        }

    }
}
